﻿using Models.Models.Sugar;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Models.Extension
{
    public static class SugarExtension
    {
        public static PageModel<T> ToPageModel<T>(this ISugarQueryable<T> queryable, int page, int limit)
        {
            var total = 0;
            var result = queryable.ToPageList(page, limit, ref total);
            return new PageModel<T>(total, result);
        }

        public static async Task<PageModel<T>> ToPageModelAsync<T>(this ISugarQueryable<T> queryable, int page, int limit)
        {
            RefAsync<int> total = 0;
            var result = await queryable.ToPageListAsync(page, limit, total);
            return new PageModel<T>(total, result);
        }
    }
}
